package com.ly.mpayment.persist.common;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

/**
 * SessionContext.java
 * session工具类
 * 
 * 2013-6-17
 * Version 1.0
 */
public class SessionContext {
	
	public static SessionContext instance;
	
	public Map<String,Object> sessionMap;
	
	private SessionContext(){
		sessionMap = new HashMap<String, Object>();
	}
	
	public static synchronized SessionContext getInstance(){
		if(null == instance){
			instance = new SessionContext();
		}
		return instance;
	}
	
	public synchronized void addSession(HttpSession session){
		if(null != session){
			sessionMap.put(session.getId(), session);
		}
	}
	
	public synchronized void removeSession(HttpSession session){
		if(null != session){
			sessionMap.remove(session.getId());
		}
	}
	
	public synchronized HttpSession getSession(String session_id){
		if(null == session_id){
			return null;
		}
		return (HttpSession) sessionMap.get(session_id);
	}

	
//	public static synchronized UserVo getUser(HttpServletRequest request){
//		String sessionId = (String) request.getParameter("sessionId");
//		HttpSession session = SessionContext.getInstance().getSession(sessionId);
//		UserVo user = (UserVo) session.getAttribute("user");
//		return user;
//	}

}
